home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 22 / Amiga Format AFCD22 (Jan 1998, Issue 106).iso / -seriously_amiga- / shareware / hardware / lcdaemon / programmer / handle / handle.c
C/C++ Source or Header  |  1997-11-05  |  5KB  |  241 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <signal.h>
  5. #include <proto/exec.h>
  6. #include <proto/dos.h>
  7. #include <exec/ports.h>
  8. #include <dos/dos.h>
  9. #include "lcd.h"
  10.  
  11. #define C(a,b,c,d,e) (((a)<<4)|((b)<<3)|((c)<<2)|((d)<<1)|(e))
  12. UBYTE customchar[]={
  13.     C(0,0,0,0,0),
  14.     C(0,0,0,0,0),
  15.     C(0,1,1,1,0),
  16.     C(0,1,0,1,0),
  17.     C(0,1,0,1,0),
  18.     C(0,1,0,1,0),
  19.     C(0,1,1,1,0),
  20.     C(0,0,0,0,0),
  21.  
  22.     C(0,0,0,0,0),
  23.     C(0,0,0,0,0),
  24.     C(0,0,1,0,0),
  25.     C(0,0,1,0,0),
  26.     C(0,0,1,0,0),
  27.     C(0,0,1,0,0),
  28.     C(0,0,1,0,0),
  29.     C(0,0,0,0,0),
  30.  
  31.     C(0,0,0,0,0),
  32.     C(0,0,0,0,0),
  33.     C(0,1,1,0,0),
  34.     C(0,0,0,1,0),
  35.     C(0,0,1,0,0),
  36.     C(0,1,0,0,0),
  37.     C(0,1,1,1,0),
  38.     C(0,0,0,0,0),
  39.  
  40.     C(0,0,0,0,0),
  41.     C(0,0,0,0,0),
  42.     C(0,1,1,0,0),
  43.     C(0,0,0,1,0),
  44.     C(0,0,1,0,0),
  45.     C(0,0,0,1,0),
  46.     C(0,1,1,0,0),
  47.     C(0,0,0,0,0),
  48.  
  49.     C(0,0,0,0,0),
  50.     C(0,0,0,0,0),
  51.     C(0,1,0,1,0),
  52.     C(0,1,0,1,0),
  53.     C(0,0,1,1,0),
  54.     C(0,0,0,1,0),
  55.     C(0,0,0,1,0),
  56.     C(0,0,0,0,0),
  57.  
  58.     C(0,0,0,0,0),
  59.     C(0,0,0,0,0),
  60.     C(0,1,1,1,0),
  61.     C(0,1,0,0,0),
  62.     C(0,0,1,0,0),
  63.     C(0,0,0,1,0),
  64.     C(0,1,1,0,0),
  65.     C(0,0,0,0,0),
  66.  
  67.     C(0,0,0,0,0),
  68.     C(0,0,0,0,0),
  69.     C(0,0,1,1,0),
  70.     C(0,1,0,0,0),
  71.     C(0,1,1,1,0),
  72.     C(0,1,0,1,0),
  73.     C(0,1,1,1,0),
  74.     C(0,0,0,0,0),
  75.  
  76.     C(0,0,0,0,0),
  77.     C(0,0,0,0,0),
  78.     C(0,1,1,1,0),
  79.     C(0,0,0,1,0),
  80.     C(0,0,0,1,0),
  81.     C(0,0,0,1,0),
  82.     C(0,0,0,1,0),
  83.     C(0,0,0,0,0)
  84. };
  85.  
  86. UBYTE bargraph[]={
  87.     C(1,1,1,1,1),
  88.     C(0,0,0,0,0),
  89.     C(0,0,0,0,0),
  90.     C(0,0,0,0,0),
  91.     C(0,0,0,0,0),
  92.     C(0,0,0,0,0),
  93.     C(1,1,1,1,1),
  94.     C(0,0,0,0,0),
  95.  
  96.     C(1,1,1,1,1),
  97.     C(1,0,0,0,0),
  98.     C(1,0,0,0,0),
  99.     C(1,0,0,0,0),
  100.     C(1,0,0,0,0),
  101.     C(1,0,0,0,0),
  102.     C(1,1,1,1,1),
  103.     C(0,0,0,0,0),
  104.  
  105.     C(1,1,1,1,1),
  106.     C(1,1,0,0,0),
  107.     C(1,1,0,0,0),
  108.     C(1,1,0,0,0),
  109.     C(1,1,0,0,0),
  110.     C(1,1,0,0,0),
  111.     C(1,1,1,1,1),
  112.     C(0,0,0,0,0),
  113.  
  114.     C(1,1,1,1,1),
  115.     C(1,1,1,0,0),
  116.     C(1,1,1,0,0),
  117.     C(1,1,1,0,0),
  118.     C(1,1,1,0,0),
  119.     C(1,1,1,0,0),
  120.     C(1,1,1,1,1),
  121.     C(0,0,0,0,0),
  122.  
  123.     C(1,1,1,1,1),
  124.     C(1,1,1,1,0),
  125.     C(1,1,1,1,0),
  126.     C(1,1,1,1,0),
  127.     C(1,1,1,1,0),
  128.     C(1,1,1,1,0),
  129.     C(1,1,1,1,1),
  130.     C(0,0,0,0,0),
  131.  
  132.     C(1,1,1,1,1),
  133.     C(1,1,1,1,1),
  134.     C(1,1,1,1,1),
  135.     C(1,1,1,1,1),
  136.     C(1,1,1,1,1),
  137.     C(1,1,1,1,1),
  138.     C(1,1,1,1,1),
  139.     C(0,0,0,0,0),
  140.  
  141. };
  142.  
  143. struct MsgPort *replyport;
  144. struct lcdmessage msg;
  145. struct lcdparams lcdpar;
  146. struct lcdscreen *scr;
  147.  
  148. int SafePutToPort(struct lcdmessage *message,STRPTR portname){
  149.     struct MsgPort *port;
  150.     Forbid();
  151.     port=FindPort(portname);
  152.     if(port) PutMsg(port,(struct Message *)message);
  153.     Permit();
  154.     return(port?TRUE:FALSE);
  155. }
  156.  
  157. int main(int argc, char **argv){
  158.  
  159.     register int i,j;
  160.  
  161.         if(replyport=CreateMsgPort()){
  162.             msg.lcd_Message.mn_Node.ln_Type=NT_MESSAGE;
  163.             msg.lcd_Message.mn_Length=sizeof(struct lcdmessage);
  164.             msg.lcd_Message.mn_ReplyPort=replyport;
  165.             msg.lcd_Priority=LCDPRI_APPLICATION;
  166.  
  167.             msg.lcd_Code=LCDMSG_ASKPARAMS;
  168.             msg.lcd_Data=&lcdpar;
  169.             if(SafePutToPort(&msg,lcdportname)){
  170.                 printf("Ask OK\n");
  171.                 WaitPort(replyport);
  172.                 GetMsg(replyport);
  173.                 msg.lcd_Code=LCDMSG_ALLOCATEHANDLE;
  174.                 msg.lcd_Data=NULL;
  175.                 msg.lcd_Priority=LCDPRI_APPLICATION-10;    /*    lower than lcdecho to show off priority :-) */
  176.                 msg.lcd_Ticks=~0;    /*    use ~0 as special case: "forever" (until deallocation)    */
  177.                 if(SafePutToPort(&msg,lcdportname)){
  178.                     WaitPort(replyport);
  179.                     GetMsg(replyport);
  180.                 }
  181.                 if(!msg.lcd_Error){
  182.                     printf("Handle OK\n");
  183.                     scr=(struct lcdscreen *)msg.lcd_Data;
  184.  
  185.                     msg.lcd_Code=LCDMSG_UPDATEHANDLE;
  186.                     msg.lcd_Data=(APTR)scr;
  187.                     strcpy(scr->screenbuffer,"Vomit \001\002\003\004\005\006\007");
  188.                     scr->ud_flags=LCDUPD_DISPLAY|LCDUPD_CUSTOMCHARNUM|LCDUPD_CUSTOMCHARDEFS;
  189.                     scr->customchardefs=customchar;
  190.                     scr->customcharnum=8;
  191.                     scr->customcharheight=8;
  192.                     SafePutToPort(&msg,lcdportname);
  193.                     WaitPort(replyport);
  194.                     GetMsg(replyport);
  195.  
  196.                     for(i=0;i<8;i++){
  197.                         msg.lcd_Code=LCDMSG_UPDATEHANDLE;
  198.                         scr->ud_flags=LCDUPD_CUSTOMCHARDEFS;
  199.                         customchar[i*8+7]=0xff;
  200.                         Delay(20);
  201.                         SafePutToPort(&msg,lcdportname);
  202.                         WaitPort(replyport);
  203.                         GetMsg(replyport);
  204.                     }
  205.                     Delay(20);
  206.  
  207.                     msg.lcd_Code=LCDMSG_UPDATEHANDLE;
  208.                     scr->ud_flags=LCDUPD_CUSTOMCHARDEFS|LCDUPD_CUSTOMCHARNUM|LCDUPD_DISPLAY;
  209.                     scr->customchardefs=bargraph;
  210.                     scr->customcharnum=6;
  211.                     scr->customcharheight=8;
  212.                     strcpy(scr->screenbuffer,"Speed:");
  213.                     for(i=6;i<scr->bufferwidth;i++){
  214.                         scr->screenbuffer[i]=' ';
  215.                     }
  216.                     for(i=0;i<lcdpar.width;i++){
  217.                         for(j=0;j<6;j++){
  218.  
  219.                             scr->screenbuffer[scr->bufferwidth+i]=j;
  220.  
  221.                             SafePutToPort(&msg,lcdportname);
  222.                             WaitPort(replyport);
  223.                             GetMsg(replyport);
  224.                             scr->ud_flags=LCDUPD_DISPLAY;
  225.                             Delay(1);
  226.                         }
  227.                     }
  228.  
  229.                     msg.lcd_Code=LCDMSG_FREEHANDLE;
  230.                     msg.lcd_Data=(APTR)scr;
  231.                     SafePutToPort(&msg,lcdportname);
  232.                     WaitPort(replyport);
  233.                     GetMsg(replyport);
  234.                 }
  235.             }
  236.             DeleteMsgPort(replyport);
  237.         }
  238.  
  239.     
  240. }
  241.